/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.terminalrodoviario;

import java.util.Collection;

/**
 *
 * @author TIAGO
 */
public class User extends BaseEntity<User>{

    // <editor-fold defaultstate="collapsed" desc="Builders">
    public User()
    {
    }
    
    public User(String name, String login, String password)
    {
        this.name=name;
        this.login=login;
        this.password=password;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Properties">
    private String name;
    private String login;
    private String password;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Gets and Sets">
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

     public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    // </editor-fold>

    public User authenticate(String login, String pwd){
        Encryption e = new Encryption();
        Collection<User> users = new User().select("Select u from User u where u.login='"+login+"'");
        for (User u : users)
            if (u.getPassword().equals(e.encrypt(pwd)))
                return u;
        return null;
    }
}
